﻿using Greg.XmlEditor.Presentation.Presenters;

namespace Greg.XmlEditor.Presentation.Commands.Concrete
{
	public class OpenCommand : CommandBase
	{
		private readonly MasterPresenter presenter;
		private readonly IInteractionManager interaction;

		public OpenCommand(MasterPresenter presenter, IInteractionManager interaction)
		{
			this.presenter = presenter;
			this.interaction = interaction;
		}

		/// <summary>
		/// Refreshes the command state.
		/// </summary>
		public override void Refresh()
		{
			this.IsEnabled = true;
		}

		/// <summary>
		/// Executes the command logics.
		/// </summary>
		public override void Invoke()
		{
			var fileName = string.Empty;
			if (!this.interaction.AskFromWhereOpenFile(ref fileName)) return;

			this.presenter.Open(fileName);
		}
	}
}
